
require 'rainbow'

module TheFox
	module VieTra
		
		class Departure
			
			def initialize(ar)
				@time_planned = nil
				@time_real = nil
				@time_planned_s = '--:--'
				@time_real_s = ''
				@countdown = nil
				
				if ar.is_a?(Hash) && ar.has_key?('departureTime')
					if ar['departureTime'].has_key?('timePlanned')
						@time_planned = ar['departureTime']['timePlanned']
						@time_planned_s = @time_planned.strftime('%H:%M')
					end
					if ar['departureTime'].has_key?('timeReal')
						@time_real = ar['departureTime']['timeReal']
						@time_real_s = @time_real.strftime('%H:%M')
					end
					if ar['departureTime'].has_key?('countdown')
						@countdown = ar['departureTime']['countdown'].to_i
					end
				end
				
				#@time_planned_s = Rainbow(@time_planned_s).bright.green
				
				
				#puts "'#{@time_real_s}' == '#{@time_planned_s}'"
				if @time_real_s == @time_planned_s
					@time_real_s = ''
				end
				# @time_real_s = Rainbow('21:30').bright.yellow
				# @time_real_s = Rainbow('21:30').yellow
				# @time_real_s = Rainbow('21:30').red
				# @time_real_s = Rainbow('21:30').bright.red
				#@time_real_s = Rainbow('21:30').red
				
				@time_planned_s = Rainbow(@time_planned_s).bright
				@time_real_s = Rainbow(@time_real_s).bright.red
				
				@countdown_s = ''
				@countdown_s = "-#{@countdown}" if @countdown
			end
			
			def to_s
				'%3s %s %s' % [@countdown_s, @time_planned_s, @time_real_s]
			end
			
		end
		
	end
end
